package com.ad.pet.app.mall;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.mall.OrderDoorInfo;
import com.ad.pet.models.remote.mall.ServiceDetail;
import com.ad.pet.models.remote.mall.SkuPirce;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by liuyixiang on 2019/11/26.
 */

public class ServiceDetailPresenter extends AbsBasePresenter implements ServiceDetailContracts.Presenter {

    private ApiService mApiService;
    private ServiceDetailContracts.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;
    @Inject
    public ServiceDetailPresenter(ApiService apiService,
                         Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(ServiceDetailContracts.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }


    @Override
    public void getServiceDetail(String oid, String sid) {
        mRxDisposable.add(mApiService.get_service_detail(oid,sid).subscribe(new AppSubscriber<ServiceDetail>(mView) {
            @Override
            public void next(ServiceDetail productDetail) {
                mView.getServiceDetialSuccess(productDetail);
            }
        }));
    }

    @Override
    public void getSkuPriceDetail(String oid, String attr_str) {
        mRxDisposable.add(mApiService.get_sku_price(oid,attr_str).subscribe(new AppSubscriber<SkuPirce>(mView) {
            @Override
            public void next(SkuPirce productDetail) {
                mView.getSkuPriceDetailSuccess(productDetail);
            }
        }));
    }

    @Override
    public void getDoorBasicInfo(String date, String shop_id) {
        mRxDisposable.add(mApiService.getDoorBasicInfo(date,shop_id).subscribe(new AppSubscriber<OrderDoorInfo>(mView) {
            @Override
            public void next(OrderDoorInfo productDetail) {
                mView.getDoorBasicInfoSuccess(productDetail);
            }
        }));
    }

    @Override
    public void upDoorOrder(String contact_name, String contact_tel, String shop_id, String pet_id, String offservice_id, String offservice_name, String offservice_sku_id, String offservice_sku_name, String appoint_offservice_date, String appoint_offservice_time, String voucher_id, String price) {
        mRxDisposable.add(mApiService.upDoorOrder( contact_name, contact_tel, shop_id, pet_id, offservice_id, offservice_name, offservice_sku_id, offservice_sku_name, appoint_offservice_date, appoint_offservice_time, voucher_id, price).subscribe(new AppSubscriber<List>(mView) {
            @Override
            public void next(List productDetail) {
                mView.upDoorOrderSuccess();
            }
        }));
    }

    @Override
    public void addService(String id,String shopid) {
        mRxDisposable.add(mApiService.addservicefav(id,shopid).subscribe(new AppSubscriber<String>(mView) {
            @Override
            public void next(String productDetail) {
                mView.addServiceSuccess();
            }
        }));
    }

    @Override
    public void cancelService(String id,String shopid) {
        mRxDisposable.add(mApiService.cancelservicefav(id,shopid).subscribe(new AppSubscriber<String>(mView) {
            @Override
            public void next(String productDetail) {
                mView.cancelServiceSuccess();
            }
        }));
    }
}
